package com.bawei.day0129.view.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;

import android.os.Bundle;
import android.widget.RadioGroup;

import com.bawei.day0129.R;
import com.bawei.day0129.base.BaseActivity;
import com.bawei.day0129.databinding.ActivityMainBinding;
import com.bawei.day0129.view.fragment.OnesFragment;
import com.bawei.day0129.viewmodel.MainViewModel;

import java.util.ArrayList;

public class MainActivity extends BaseActivity<MainViewModel, ActivityMainBinding> {

    @Override
    protected int initLayout() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        ArrayList<Fragment> list = new ArrayList<>();
        list.add(new OnesFragment());
        list.add(new OnesFragment());
        list.add(new OnesFragment());
        dataBinding.vg.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @NonNull
            @Override
            public Fragment getItem(int position) {
                return list.get(position);
            }

            @Override
            public int getCount() {
                return list.size();
            }
        });
        dataBinding.rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                switch (i){
                    case R.id.rb1:
                        dataBinding.vg.setCurrentItem(0);
                        break;
                    case R.id.rb2:
                        dataBinding.vg.setCurrentItem(1);
                        break;
                    case R.id.rb3:
                        dataBinding.vg.setCurrentItem(2);
                        break;
                }
            }
        });
    }
}